package dao

import (
	"6-11zk/inits"
	"6-11zk/model"
)

func CreateProduct(product *model.Product) error {
	return inits.DB.Debug().Create(&product).Error
}

func ProductList(group string) (result []*model.Product, err error) {
	tx := inits.DB.Debug()
	if group != "" {
		tx = tx.Where("product_grouping LIKE ?", group)
	}
	err = tx.Find(&result).Error
	if err != nil {
		return nil, err
	}
	return
}

func UpdateStatus() error {
	return inits.DB.Debug().Updates("status").Error
}
func Show(id int) (result *model.Product, err error) {
	err = inits.DB.Debug().Where("id = ?", id).Limit(1).Find(&result).Error
	if err != nil {
		return nil, err
	}
	return
}
